// 接口地址管理
let express = require('express');
let user = require('../controls/user');
let weekly = require('../controls/weekly');
const file = require('../controls/file')
let api = require('../config/api');
const multer = require("multer")
const uuid = require('uuid')
//自定义存储规则
const custom = multer.diskStorage({
    destination(req,file,cb){
        cb(null,"./files")
    },  
    filename(req,file,cb){
        //获取文件的后缀名 并改成小写
        let extension = file.originalname.substr(file.originalname.lastIndexOf(".")).toLowerCase()
        //生成唯一的名称
        let filename = uuid.v1() + extension;
        //新的文件名放进回调函数
        cb(null,filename)
    }
})
//使用自定义存储规则
const uploadPoint = multer({storage:custom})
let router = express.Router();

// user-用户管理 
router.post(api.userLogin, user.login);
router.post(api.userLogout, user.logout);
router.post(api.userAdd, user.add);
router.post(api.userUpdateInfo, user.updateInfo);
router.post(api.userUpdateState, user.updateState);
router.post(api.userDetail, user.detail);
router.post(api.userList, user.list);
router.post(api.userInfo, user.info);
router.post(api.userDel, user.delUser);
//文件管理
router.post(api.fileAdd,uploadPoint.array("file"),file.add);
router.post(api.fileDel,file.del);
router.post(api.fileUpdate,file.update);
router.post(api.fileList,file.list);
// weekly-周报管理
router.post(api.weeklyAdd, weekly.add);
router.post(api.weeklyUpdateInfo, weekly.updateInfo);
router.post(api.weeklyUpdateState, weekly.updateState);
router.post(api.weeklyDetail, weekly.detail);
router.post(api.weeklyList, weekly.list);

module.exports = router;